﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using HF.Software.ClassLib;

namespace HF.Software
{
    /// <summary>
    /// hef创建于2015.02.04
    /// 双屏配置文件读写
    /// </summary>
    public partial class frmDoubleScreen : Form
    {
        #region event

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (null == this.oConfig) return;

            IniModelDataCollection oDataCollection = new IniModelDataCollection();
            IniWrite oIniWrite = new IniWrite();

            POS oPos = this.oConfig.POS;

            try
            {
                PropertyInfo[] oFields = oPos.GetType().GetProperties();

                foreach (PropertyInfo oInfo in oFields)
                {
                    IniModel oConfigIni = new IniModel();
                    oConfigIni.IN_Section = "POS";
                    oConfigIni.IN_Key = oInfo.Name;
                    oConfigIni.IN_Value = Convert.ToString(oInfo.GetValue(oPos, null));
                    switch (oConfigIni.IN_Key.Trim())
                    {
                        case "DoubleScreenPhotoTimes"://显示广告时间
                            oConfigIni.IN_Value = this.txtAdDate.Text.Trim();
                            break;

                        case "DoubleScreenState"://是否开启双屏
                            if (this.chkDSState.Checked)
                                oConfigIni.IN_Value = "T";
                            else
                                oConfigIni.IN_Value = "F";
                            break;

                        case "DoubleScreenSeat"://是否开启双屏选座
                            if (this.chkDSSeat.Checked)
                                oConfigIni.IN_Value = "T";
                            else
                                oConfigIni.IN_Value = "F";
                            break;
                    }

                    oDataCollection.Add(oConfigIni);
                }

                foreach (IniModel oIniModel in oDataCollection)
                {
                    oIniWrite.Write(oIniModel.IN_Section, oIniModel.IN_Key, oIniModel.IN_Value);
                }
                MessageBox.Show("双屏更新成功！", "提示");
            }
            catch (Exception ex)
            {
                this.oLog.fnLog("201502051405更新票务失败：" + ex.ToString());
                MessageBox.Show("双屏更新失败！", "提示");
            }
        }

        #endregion

        #region create

        public frmDoubleScreen()
        {
            InitializeComponent();
        }

        private void frmDoubleScreen_Load(object sender, EventArgs e)
        {
            if (null == this.oConfig) return;

            this.txtAdDate.Text = this.oConfig.POS.DoubleScreenPhotoTimes.Trim();

            if (string.IsNullOrWhiteSpace(this.oConfig.POS.DoubleScreenPhotoTimes.Trim()))
                this.txtAdDate.Text = "1";

            this.chkDSState.Checked = this.oConfig.POS.DoubleScreenState;

            this.chkDSSeat.Checked = this.oConfig.POS.DoubleScreenSeat;
        }

        #endregion

        #region var

        AppConfig oConfig = new AppConfig();
        private ClsLog oLog = new ClsLog(Application.StartupPath + @"\log\set\" + DateTime.Now.ToString("yyyyMMddHH") + ".txt");

        #endregion

    }
}